import 'dart:io';

import 'package:card_topia/my_router.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../design_specifications.dart';

///自定义appbar

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  const CustomAppBar(
      {super.key,
      this.title,
      this.actions,
      this.isBack = true,
      this.showLeading = false,
      this.iconColor,
      this.isDark = false});

  final String? title;
  final List<Widget>? actions;
  final bool isBack;
  final bool showLeading;
  final Color? iconColor;
  final bool isDark;

  @override
  Widget build(BuildContext context) {
    return AppBar(
      backgroundColor: Colors.transparent,
      automaticallyImplyLeading: false,
      elevation: 0,
      systemOverlayStyle: Platform.isAndroid
          ? SystemUiOverlayStyle(
              systemNavigationBarColor: scaffoldBackgroundColor,
              statusBarColor: Colors.transparent,
              statusBarIconBrightness: isDark?Brightness.light:Brightness.dark)
          : (isDark?SystemUiOverlayStyle.light:SystemUiOverlayStyle.dark),
      foregroundColor: isDark?Colors.white:textColor,
      actions: actions,
      leading: showLeading
          ? InkWell(
              onTap: () => MyRouter.pop(),
              child: Icon(
                isBack ? CupertinoIcons.left_chevron : Icons.close_rounded,
              ),
            )
          : null,
      centerTitle: false,
      title: Text(
        title ?? "",
        style:
            TextStyle(fontSize: 18.sp, color: textColor, fontFamily: harmony),
      ),
    );
  }

  @override
// TODO: implement preferredSize
  Size get preferredSize => AppBar().preferredSize;
}
